<cfquery name = "qblogsincategory" datasource="#request.dsn#">
SELECT * FROM blog_posts JOIN contacts_users ON contacts_users.id = blog_posts.userid
WHERE cid = <cfqueryparam value="#id#" cfsqltype="cf_sql_integer">
<cfif NOT pid IS 0>AND userid = <cfqueryparam value="#pid#" cfsqltype="cf_sql_integer"></cfif>
ORDER BY blog_posts.b_postedon DESC
</cfquery>

<cfquery name = "qblogcount" datasource="#request.dsn#">
SELECT count(*) AS totalrecords FROM blog_posts JOIN contacts_users ON contacts_users.id = blog_posts.userid
WHERE cid = <cfqueryparam value="#id#" cfsqltype="cf_sql_integer">
<cfif NOT pid IS 0>AND userid = <cfqueryparam value="#pid#" cfsqltype="cf_sql_integer"></cfif>
ORDER BY blog_posts.b_postedon DESC
</cfquery>

